package com.ruoyi.doctor.service.impl;

import com.ruoyi.doctor.domain.DoctorPatient;
import com.ruoyi.doctor.domain.DoctorPatientHistory;
import com.ruoyi.doctor.mapper.DoctorVisitsMapper;
import com.ruoyi.doctor.service.DoctorVisitsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Random;

@Service
public class DoctorVisitsServiceImpl implements DoctorVisitsService {

    @Autowired
    DoctorVisitsMapper doctorVisitsMapper;

    //查询患者和挂号列表
    @Override
    public List<DoctorPatient> queryPatient() {
        return doctorVisitsMapper.queryPatient();
    }

    //根据患者id查询数据
    @Override
    public DoctorPatient queryById(int patientId) {
        return doctorVisitsMapper.queryById(patientId);
    }

    @Override
    public String addPatient(DoctorPatientHistory patientHistory,int historyPatientId) {
        //将传递的患者数据赋值给对象
        patientHistory.setHistoryPatientId(historyPatientId);
        //生成随机病例
        String Bl = "BL"+ (new Random().nextInt(899999) + 100000);
        patientHistory.setHistoryNumber(Bl);
        System.out.println(Bl);

        int i = doctorVisitsMapper.addPatient(patientHistory);
        if(i != 0){
            return doctorVisitsMapper.queryByPatientId(historyPatientId);
        }
        return null;
    }

    @Override
    public int addCheck(int patientId, int[] checkId) {
        int x = 0;
        for (int i = 0; i < checkId.length; i++) {
            x = doctorVisitsMapper.addCheck(patientId, checkId[i]);
        }
        return x;
    }

    @Override
    public int addDrug(int patientId, int[] drug,int [] num) {
        int x = 0;
        for (int i = 0; i < drug.length; i++) {
            System.out.println("药品名称"+drug[i]+":"+"药品数量"+num[i]);
            x = doctorVisitsMapper.addDrug(patientId,drug[i],num[i]);
        }
        return x;
    }

    @Override
    public int updateStatus(int patientId) {
        return doctorVisitsMapper.updateStatus(patientId);
    }


}
